﻿
namespace CmdArgs.Validation.Options
{
    using System.Collections.Generic;
    using CmdArgs.Settings;

    /// <summary>
    /// This class implements template method patters for validators that 
    /// validates only value of each parameter without any context like for example their relations.
    /// </summary>
    public abstract class ValueValidatorTemplate : IOptionValidator
    {
        /// <summary>
        /// Validates the specified values of option.
        /// The template method that calls <see cref="Validate(string,OptionSettings)"/>.
        /// </summary>
        /// <param name="values">The parameters values.</param>
        /// <param name="optionSettings">Settings of the option whose parameters are validated.</param>
        /// <returns>The validation result with list of validation errors.</returns>
        public ValidationResult Validate(IEnumerable<string> values, OptionSettings optionSettings)
        {
            IList<ValidationResult> results = new List<ValidationResult>();
            foreach (var value in values)
            {
                results.Add(this.Validate(value, optionSettings));
            }

            return new ValidationResult(results);
        }

        /// <summary>
        /// Validates the specified value.
        /// </summary>
        /// <param name="value">The value of the parameter.</param>
        /// <param name="optionSettings">Settings of the option whose parameter is validated.</param>
        /// <returns>The validation result with list of validation errors.</returns>
        protected abstract ValidationResult Validate(string value, OptionSettings optionSettings);
    }
}
